home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77558_sh_page.js < prev    next >
Encoding:
Text File  |  2003-02-21  |  28.2 KB  |  1,178 lines

  1. // ==============================================================
  2. //     Microsoft Server Appliance
  3. //     Page-level JavaScript functions
  4. //
  5. // Copyright (c) Microsoft Corporation.  All rights reserved.
  6. //
  7. // ==============================================================
  8.  
  9. <!-- Copyright (c) Microsoft Corporation.  All rights reserved.-->
  10.  
  11. var blnOkayToLeavePage = true;
  12.  
  13. function SetOkayToLeavePage()
  14. {
  15.     blnOkayToLeavePage = true;
  16. }
  17.  
  18. function ClearOkayToLeavePage()
  19. {
  20.     blnOkayToLeavePage = false;
  21. }
  22.  
  23. function SetPageChanged(valChanged)
  24. {
  25.     if ( valChanged )
  26.     {
  27.         ClearOkayToLeavePage();
  28.     }
  29.     else
  30.     {
  31.         SetOkayToLeavePage();
  32.         SA_StoreInitialState();
  33.         
  34.     }
  35.  
  36. }
  37.  
  38. function SA_IsOkToChangePage()
  39. {
  40.     if ( SA_HasStateChanged() )
  41.         return false;
  42.     else
  43.         return true;
  44. }
  45.  
  46. //-------------------------------------------------------------------------
  47. //
  48. // Function : GetCurrentTabURL
  49. //
  50. // Synopsis : Get the URL of the currently active tab
  51. //
  52. // Arguments: None 
  53. //
  54. // Returns  : None
  55. //
  56. //-------------------------------------------------------------------------
  57.     
  58. function GetCurrentTabURL() 
  59. {
  60.     var strReturnURL;
  61.     var strStart;
  62.     var strEnd;
  63.     var intTab;
  64.  
  65.     strReturnURL = document.location.search;
  66.     strStart = strReturnURL.indexOf("Tab=");
  67.     if (strStart != -1)
  68.     {
  69.        strEnd = strReturnURL.indexOf("&", strStart+4);
  70.        if (strEnd != -1)
  71.        {
  72.            intTab = strReturnURL.substring(strStart+4, strEnd);
  73.        }
  74.        else
  75.        {
  76.            intTab = strReturnURL.substring(strStart+4, strReturnURL.length);
  77.        }
  78.     }
  79.     if (intTab==null)
  80.     {
  81.         intTab=0;
  82.     }
  83.     return GetTabURL(intTab);
  84. }
  85.  
  86. //-------------------------------------------------------------------------
  87. //
  88. // Function : OpenNewPage
  89. //
  90. // Synopsis : Opens a new browser window for the specified URL
  91. //
  92. // Arguments: VirtualRoot(IN) - current virtual root 
  93. //            TaskURL(IN)   - URL to open
  94. //
  95. // Returns  : None
  96. //
  97. //-------------------------------------------------------------------------
  98. function OpenNewPage(VirtualRoot, TaskURL, WindowFeatures) {
  99.     var strURL;
  100.  
  101.   strURL = VirtualRoot + TaskURL;
  102.   if ( WindowFeatures != 'undefined' && WindowFeatures.length > 0 )
  103.       {
  104.         window.open(strURL, '_blank', WindowFeatures)
  105.       }
  106.   else
  107.       {
  108.         window.open(strURL, '_blank')
  109.       }
  110.   return true;
  111. }
  112.  
  113. //-------------------------------------------------------------------------
  114. //
  115. // Function : OpenRawPageEx
  116. //
  117. // Synopsis : Opens a new browser window for the specified URL
  118. //
  119. // Arguments: TaskURL(IN)   - URL to open
  120. //               WindowFeatures - parameters for window features in window.open call
  121. //
  122. // Returns  : None
  123. //
  124. //-------------------------------------------------------------------------
  125. function OpenRawPageEx(TaskURL, WindowFeatures) {
  126.   if ( WindowFeatures != 'undefined' && WindowFeatures.length > 0 )
  127.       {
  128.         window.open(TaskURL, '_blank', WindowFeatures)
  129.       }
  130.   else
  131.       {
  132.         window.open(TaskURL, '_blank')
  133.       }
  134.   return true;
  135. }
  136.  
  137. //-------------------------------------------------------------------------
  138. //
  139. // Function : OpenRawPage
  140. //
  141. // Synopsis : Opens a new browser window for the specified URL
  142. //
  143. // Arguments: VirtualRoot(IN) - current virtual root 
  144. //            TaskURL(IN)   - URL to open
  145. //
  146. // Returns  : None
  147. //
  148. //-------------------------------------------------------------------------
  149. function OpenRawPage(TaskURL) {
  150.   return OpenRawPageEx(TaskURL, '');
  151. }
  152.  
  153.  
  154. //-------------------------------------------------------------------------
  155. //
  156. // Function : OpenNormalPage
  157. //
  158. // Synopsis : , 
  159. //            and sets the current window to open it.
  160. //
  161. // Arguments: VirtualRoot(IN) - current virtual root 
  162. //            TaskURL(IN)   - URL to open
  163. //
  164. // Returns  : None
  165. //
  166. //-------------------------------------------------------------------------
  167.  
  168. function OpenNormalPage(VirtualRoot, TaskURL) {
  169.     var strURL;
  170.  
  171. // This section will check to see if the user has made any changes to the page
  172. // which might be lost if we leave. Ask the user if this is the case.
  173.  
  174.   if (!SA_IsOkToChangePage() )
  175.   {
  176.     if (!confirm(GetUnsavedChangesMessage()) )
  177.     {
  178.         return false;
  179.     }
  180.   }
  181.   strURL = VirtualRoot + TaskURL;
  182.   strURL = SA_MungeURL(strURL, SAI_FLD_PAGEKEY, g_strSAIPageKey);
  183.   top.location = strURL;
  184. }
  185.  
  186. function SA_OnOpenNormalPage(sRoot, sURL, sReturnURL)
  187. {
  188.     if ( sReturnURL.length <= 0 )
  189.     {
  190.         sReturnURL = top.location.href;
  191.     }
  192.  
  193.     sReturnURL = SA_MungeURL(sReturnURL, "R", ""+Math.random());
  194.     sURL = SA_MungeURL(sURL, "ReturnURL", sReturnURL);
  195.     
  196.     OpenNormalPage(sRoot, sURL)
  197.     return true;
  198. }
  199.  
  200.  
  201. function SA_OnOpenPropertyPage(sRoot, sURL, sReturnURL, sTaskTitle)
  202. {
  203.     if ( sReturnURL.length <= 0 )
  204.     {
  205.         sReturnURL = top.location.href;
  206.     }
  207.  
  208.     sReturnURL = SA_MungeURL(sReturnURL, "R", ""+Math.random());
  209.         
  210.     
  211.     OpenPage(sRoot, sURL, sReturnURL, sTaskTitle)
  212.     return true;
  213. }
  214.  
  215. //-------------------------------------------------------------------------
  216. //
  217. // Function : OpenPage
  218. //
  219. // Synopsis : Builds a URL, adding a ReturnURL and a random number(R), 
  220. //            and sets the current window to open it.
  221. //
  222. // Arguments: VirtualRoot(IN) - current virtual root 
  223. //            TaskURL(IN)   - URL to open
  224. //            ReturnURL(IN) - URL to mark as return URL for the TaskURL  
  225. //            strTitle(IN) - title of wizard 
  226. //
  227. // Returns  : None
  228. //
  229. //-------------------------------------------------------------------------
  230.  
  231. function OpenPage(VirtualRoot, TaskURL, ReturnURL, strTitle) {
  232.     var strURL;
  233.     var strQueryString;
  234.     var strCurrentURL;
  235.     var i;
  236.     var intReturnURLIndex;
  237.  
  238.     //alert("TaskURL: " + TaskURL);
  239.     //alert("ReturnURL: " + ReturnURL);
  240.     //alert("top.location: " + top.location);
  241.  
  242.     
  243.     if (!SA_IsOkToChangePage() )
  244.       {
  245.         if (!confirm(GetUnsavedChangesMessage()) )
  246.         {
  247.             return false;
  248.         }
  249.       }
  250.  
  251.     //
  252.     // Remove Random number param from ReturnURL
  253.     //
  254.     //alert("Before removing R param ReturnURL: " + ReturnURL);
  255.     ReturnURL = SA_MungeURL(ReturnURL, "R", ""+Math.random());
  256.     //alert("After ReturnURL: " + ReturnURL);
  257.     
  258.     //i = ReturnURL.indexOf('&R=');
  259.     //if (i != -1)
  260.     //{
  261.     //    ReturnURL = ReturnURL.substring(0, i);
  262.     //}
  263.     //else
  264.     //{
  265.     //    i = ReturnURL.indexOf('?R=');
  266.     //    if (i != -1)
  267.     //    {
  268.     //    ReturnURL = ReturnURL.substring(0, i);
  269.     //    }
  270.     //}
  271.     //i = ReturnURL.indexOf('?')
  272.     //if ( i != -1 )
  273.     //{
  274.     //ReturnURL = ReturnURL + "&R=" + Math.random();
  275.     //}
  276.     //else
  277.     //{
  278.     //ReturnURL = ReturnURL + "?R=" + Math.random();
  279.     //}
  280.  
  281.     
  282.     
  283.     i = TaskURL.indexOf('&ReturnURL=')
  284.     if (i != -1)
  285.     {
  286.         strURL = TaskURL.substring(0, i);
  287.     }
  288.  
  289.  
  290.        // JK 1-16-01
  291.        // Strip TaskURL of the Random number parameter
  292.     //strURL = SA_MungeURL(TaskURL, "R", "");
  293.     i = TaskURL.indexOf('&R=');
  294.     if (i != -1)
  295.     {
  296.         strURL = TaskURL.substring(0, i);
  297.     }
  298.     else
  299.     {
  300.         i = TaskURL.indexOf('?R=');
  301.         if (i != -1)
  302.         {
  303.             strURL = TaskURL.substring(0, i);
  304.         }
  305.         else
  306.         {
  307.             strURL = TaskURL;
  308.         }
  309.     }
  310.     strURL = '&URL=' + EscapeArg(strURL);
  311.  
  312.     if (TaskURL.indexOf('ReturnURL') == -1)
  313.     {
  314.         if ( (ReturnURL == null) || (ReturnURL == '') )
  315.         {
  316.             strQueryString = window.location.search;
  317.             i = strQueryString.indexOf('&R=');
  318.             if (i != -1)
  319.             {
  320.                 strQueryString = strQueryString.substring(0, i);
  321.             }
  322.             else
  323.             {
  324.                 i = strQueryString.indexOf('?R=');
  325.                 if (i != -1)
  326.                 {
  327.                     strQueryString = strQueryString.substring(0, i);
  328.                 }
  329.             }
  330.             intReturnURLIndex = strQueryString.indexOf('ReturnURL');
  331.             if (intReturnURLIndex != -1)
  332.             {
  333.                 strQueryString = strQueryString.substring(0, intReturnURLIndex);
  334.             }
  335.             strCurrentURL = window.location.pathname + strQueryString;
  336.         }
  337.         else
  338.         {
  339.             // JK 1-16-01
  340.             // Do not remove returnURL parameter contained within returnURL
  341.             //
  342.             //i = ReturnURL.indexOf('&ReturnURL=');
  343.             //if (i != -1)
  344.             //{
  345.             //    ReturnURL = ReturnURL.substring(0,i);
  346.             //}
  347.  
  348.             strCurrentURL = EscapeArg(ReturnURL);
  349.         }
  350.  
  351.         strURL += "&ReturnURL=";
  352.         if (strCurrentURL.indexOf('/', 1) != -1 && strCurrentURL.substr('..', 0, 2) == -1)
  353.         {
  354.             strURL += "..";
  355.         }
  356.         strURL += strCurrentURL;
  357.     }
  358.  
  359.     strURL += "&R=" + Math.random();
  360.     strURL += "&" + SAI_FLD_PAGEKEY + "=" + g_strSAIPageKey;
  361.     strURL = 'Title=' + EscapeArg(strTitle) + strURL;
  362.     strURL = VirtualRoot + 'sh_taskframes.asp?' + strURL;
  363.  
  364.     top.location = strURL;
  365. }
  366.  
  367.  
  368. //-------------------------------------------------------------------------
  369. //
  370. // Function : GetServerName
  371. //
  372. // Synopsis :  Return server name as specified in browser address bar
  373. //
  374. // Arguments: None
  375. //
  376. // Returns  : server name object
  377. //
  378. //-------------------------------------------------------------------------
  379.  
  380. function GetServerName() 
  381. {
  382.     return window.location.host;
  383. }
  384.  
  385.  
  386. //-------------------------------------------------------------------------
  387. //
  388. // Function : IsIE
  389. //
  390. // Synopsis : Is browser IE
  391. //
  392. // Arguments: None
  393. //
  394. // Returns  : true/false
  395. //
  396. //-------------------------------------------------------------------------
  397.  
  398. function IsIE() 
  399. {
  400.     
  401.     if (navigator.userAgent.indexOf('MSIE')>-1)
  402.         return true;
  403.     else
  404.         return false;
  405. }
  406.  
  407.  
  408.  
  409. //-------------------------------------------------------------------------
  410. //
  411. // Function : Trim
  412. //
  413. // Synopsis : remove all spaces from a string
  414. //
  415. // Arguments: str(IN) - string to modify
  416. //
  417. // Returns  : modified string
  418. //
  419. //-------------------------------------------------------------------------
  420.  
  421. function Trim(str) 
  422. {
  423.     var res="", i, ch;
  424.     for (i=0; i < str.length; i++) {
  425.         ch = str.charAt(i);
  426.         if (ch != ' '){
  427.             res = res + ch;
  428.         }
  429.     }
  430.     return res;
  431. }
  432.  
  433. //-------------------------------------------------------------------------
  434. //
  435. // Function : BlurLayer
  436. //
  437. // Synopsis : hide layer
  438. //
  439. // Arguments: None
  440. //
  441. // Returns  : None
  442. //
  443. //-------------------------------------------------------------------------
  444.  
  445. function BlurLayer()
  446. {
  447.     document.menu.visibility = "hide";
  448. }
  449.  
  450.  
  451.  
  452. //---------------------------------------------------------------
  453. // Confirm tab change support global variables
  454. //---------------------------------------------------------------
  455. var aCSAFormFields = null;
  456.  
  457. //-------------------------------------------------------------------------
  458. //
  459. // Object:         CSAFormField
  460. //
  461. // Synopsis:    This object is used to track form field state changes
  462. //
  463. // Arguments:    [in] nameIn name of form field
  464. //                [in] valueIn initial value of form field
  465. //                [in] statusIn initial status of form field
  466. //
  467. // Returns:     Nothing
  468. //
  469. //-------------------------------------------------------------------------
  470. function CSAFormField(formNameIn, nameIn, valueIn, statusIn )
  471. {
  472.     this.FormName = formNameIn;
  473.     this.Name = nameIn;
  474.     this.Value = valueIn;
  475.     this.Status = statusIn;
  476. }
  477.  
  478.  
  479. //-------------------------------------------------------------------------
  480. //
  481. // Function:    SA_StoreInitialState
  482. //
  483. // Synopsis:    Store the initial state of all form fields on this page.
  484. //
  485. // Arguments:    None
  486. //
  487. // Returns:     Nothing
  488. //
  489. //-------------------------------------------------------------------------
  490. function SA_StoreInitialState()
  491. {    
  492.     var x;
  493.     var y;
  494.     var z;
  495.     var formFieldCount;
  496.  
  497.     formFieldCount = 0;    
  498.     for( x = 0; x < document.forms.length; x++ )
  499.     {
  500.         formFieldCount += document.forms[x].elements.length;
  501.     }
  502.     
  503.     aCSAFormFields = new Array(formFieldCount);
  504.     
  505.     z = 0;
  506.     for( x = 0; x < document.forms.length; x++ )
  507.     {
  508.         for ( y = 0; y < document.forms[x].elements.length; y++)
  509.         {
  510.             aCSAFormFields[z] = new CSAFormField(
  511.                                     document.forms[x].name,
  512.                                     document.forms[x].elements[y].name,
  513.                                     document.forms[x].elements[y].value,
  514.                                     document.forms[x].elements[y].status );
  515.             z++;
  516.         }
  517.     }
  518.  
  519. }
  520.  
  521.  
  522. //-------------------------------------------------------------------------
  523. //
  524. // Function:     SA_HasStateChanged
  525. //
  526. // Synopsis:    Check to see if any of the form fields on this page have
  527. //                changed from their initial state.
  528. //
  529. // Arguments: None
  530. //
  531. // Returns:     True if changes were made, False if form is unchanged.
  532. //
  533. //-------------------------------------------------------------------------
  534. function SA_HasStateChanged()
  535. {    
  536.     var x;
  537.     var y;
  538.     var z;
  539.  
  540.  
  541.     if ( aCSAFormFields == null ) return false;
  542.  
  543.  
  544.     
  545.     z = 0;
  546.     for( x = 0; x < document.forms.length; x++ )
  547.     {
  548.         for ( y = 0; y < document.forms[x].elements.length; y++)
  549.         {
  550.             var ff = aCSAFormFields[z];
  551.             
  552.             if ( ff.Name !=     document.forms[x].elements[y].name )
  553.             {
  554.                 SA_TraceOut("SA_HasStateChanged", "Field " + ff.Name + "\r\nUnexpected error, form field name changed.");
  555.                 return true;
  556.             }
  557.             
  558.             if ( ff.Value !=     document.forms[x].elements[y].value )
  559.             {
  560.                 //SA_TraceOut("SA_HasStateChanged", "Form:" + ff.FormName + "\r\nField:" + ff.Name + "\r\nStarting Value:" + ff.Value + "  Ending Value:" + document.forms[x].elements[y].value);
  561.                 return true;
  562.             }
  563.             
  564.             if ( ff.Status != document.forms[x].elements[y].status)
  565.             {
  566.                 //SA_TraceOut("SA_HasStateChanged", "Form:" + ff.FormName + "\r\nField:" + ff.Name + "\r\nValue:" + ff.Value+ "\r\nStarting Status:" + ff.Status + "  Ending Status:" + document.forms[x].elements[y].status);
  567.                 return true;
  568.             }
  569.             
  570.             z++;
  571.         }
  572.     }
  573.     return false;
  574. }
  575.  
  576.  
  577.  
  578. //---------------------------------------------------------------
  579. // Client side script debugging 
  580. //---------------------------------------------------------------
  581. var sa_bDebugEnabled = true;
  582.  
  583. //-------------------------------------------------------------------------
  584. //
  585. // Function:     
  586. //
  587. // Synopsis:
  588. //
  589. // Arguments:
  590. //
  591. // Returns: 
  592. //
  593. //-------------------------------------------------------------------------
  594. function SA_IsDebugEnabled()
  595. {
  596.     //return sa_bDebugEnabled;
  597.     return GetIsDebugEnabled();
  598. }
  599.  
  600.  
  601. //-------------------------------------------------------------------------
  602. //
  603. // Function:     
  604. //
  605. // Synopsis:
  606. //
  607. // Arguments:
  608. //
  609. // Returns: 
  610. //
  611. //-------------------------------------------------------------------------
  612. function SA_TraceOut(fn, msg)
  613. {
  614.     if ( SA_IsDebugEnabled() )
  615.     {
  616.         objForm = SA_FindForm("frmDebug");
  617.         if ( null == objForm )
  618.         {
  619.             //alert("Function: " + fn + "\r\n\r\n" + msg );
  620.         }
  621.         else
  622.         {
  623.             if ( objForm.txtDebugOut.value.length > 1 )
  624.                 objForm.txtDebugOut.value += "\r\nFunction: " + fn + " " + msg;
  625.             else
  626.                 objForm.txtDebugOut.value = "Function: " + fn + " " + msg;
  627.         }
  628.     }
  629. }
  630.  
  631.  
  632. function SA_FindForm(formName)
  633. {
  634.     var x;
  635.  
  636.     if ( top.document.forms.length > 0 )
  637.     {
  638.         for( x = 0; x < top.document.forms.length; x++ )
  639.         {
  640.             //alert( "Found form: " + top.document.forms[x].name );
  641.             if ( formName == top.document.forms[x].name )
  642.             {
  643.                 return top.document.forms[x];
  644.             }
  645.         }
  646.     }
  647.     else 
  648.     {
  649.         //alert( "Form count: " + parent.main.document.forms.length );
  650.         for( x = 0; x < parent.main.document.forms.length; x++ )
  651.         {
  652.             //alert( "Found form: " + parent.main.document.forms[x].name );
  653.             if ( formName == parent.main.document.forms[x].name )
  654.             {
  655.                 return parent.main.document.forms[x];
  656.             }
  657.         }
  658.         
  659.     }
  660.     return null;
  661. }
  662.  
  663.  
  664. //---------------------------------------------------------------------------------
  665. // Function:    
  666. //    SA_MungeURL(var sURL, var sParamName, var sParamValue )
  667. //
  668. // Synopsis:    
  669. //    Add, Update, or Delete parameters to a query string URL. If the parameter is not in 
  670. //    the URL it is added. If it exists, it's value is updated. If the parameter value is blank
  671. //    then the parameter is removed from the URL.
  672. //        
  673. //    The URL must be non-blank on input. If a blank URL is passed an error message is 
  674. //    displayed and a empty string is returned.
  675. //
  676. // Arguments:    
  677. //    sURL - Non blank URL that is to be changed. 
  678. //    sParamName - Name of QueryString parameter
  679. //    sParamValue - Value of the parameter
  680. //
  681. // Returns:    
  682. //    Updated query string URL, empty string if an error occurs.
  683. //
  684. //---------------------------------------------------------------------------------
  685. function SA_MungeURL(sURL, sParamName, sParamValue)
  686. {
  687.     var i;
  688.     var oException;
  689.  
  690.     //
  691.     // Validate arguments
  692.     //
  693.     if ( sURL == null )
  694.     {
  695.         sURL = "";
  696.     }
  697.     if ( (typeof sURL) != "string" )
  698.     {
  699.         sURL = "" + sURL;
  700.     }
  701.  
  702.     if ( sParamName == null )
  703.     {
  704.         SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is null");
  705.         return "";
  706.     }
  707.     if ( (typeof sParamName) != "string" )
  708.     {
  709.         sParamName = "" + sParamName;
  710.     }
  711.     
  712.     if ( sParamValue == null )
  713.     {
  714.         sParamValue = "";
  715.     }
  716.     if ( (typeof sParamValue) != "string" )
  717.     {
  718.         sParamValue = "" + sParamValue;
  719.     }
  720.  
  721.     if ( sURL.length <= 0 )
  722.     {
  723.         SA_TraceOut("SA_MungeURL", "Invalid argument: sURL is empty");
  724.         return "";
  725.     }
  726.  
  727.     if ( sParamName.length <= 0 )
  728.     {
  729.         SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is empty");
  730.         return "";
  731.     }
  732.  
  733.     //
  734.     // Munge the URL
  735.     //
  736.     try
  737.     {
  738.         i = sURL.indexOf("?"+sParamName+"=");
  739.         if ( i < 0 )
  740.             {
  741.             i = sURL.indexOf("&"+sParamName+"=");
  742.             }
  743.     
  744.         if ( i > 0 )
  745.         {
  746.             //SA_TraceOut("SA_MungeURL","Found parameter: " + sParamName );
  747.             var sURL1 = sURL.substring(0, i);
  748.             var sURL2 = sURL.substring(i+1);
  749.  
  750.             //SA_TraceOut("SA_MungeURL", "sURL1: " + sURL1);
  751.             //SA_TraceOut("SA_MungeURL", "sURL2: " + sURL2);
  752.  
  753.             i = sURL2.indexOf("&");
  754.             if ( i > 0 )
  755.             {
  756.                 sURL2 = sURL2.substring(i);
  757.             }
  758.             else
  759.             {
  760.                 sURL2 = "";
  761.             }
  762.  
  763.             if (sParamValue.length > 0)
  764.                 {
  765.                 //SA_TraceOut("SA_MungeURL","Value: " + sParamValue);
  766.                 if (sURL1.indexOf("?") > 0 )
  767.                     {
  768.                     sURL = sURL1 + "&" + sParamName + "=" 
  769.                                     + EscapeArg(sParamValue) + sURL2;
  770.                     }
  771.                 else
  772.                     {
  773.                     sURL = sURL1 + "?" + sParamName + "=" 
  774.                                     + EscapeArg(sParamValue) + sURL2;
  775.                     }
  776.                 }
  777.             else
  778.                 {
  779.                 if (sURL1.indexOf("?") > 0)
  780.                     {
  781.                     sURL = sURL1 + sURL2;
  782.                     }
  783.                 else
  784.                     {
  785.                     sURL = sURL1 + "?" + sURL2.substring(1);
  786.                     }
  787.                 }
  788.         
  789.         }
  790.         else
  791.         {
  792.             if ( sParamValue.length > 0 )
  793.             {
  794.                 if ( 0 >  sURL.indexOf("?") )
  795.                 {
  796.                     sURL += '?' + sParamName + '=' + EscapeArg(sParamValue);
  797.                 }
  798.                 else
  799.                 {
  800.                     sURL += '&' + sParamName + '=' + EscapeArg(sParamValue);
  801.                 }
  802.             }
  803.         }
  804.     }
  805.     catch(oException)
  806.         {
  807.         SA_TraceOut("SA_MungeURL", 
  808.                     "SA_MungeURL encountered exception: " 
  809.                     + oException.number 
  810.                     + " " 
  811.                     + oException.description);
  812.         }
  813.     return sURL;
  814. }
  815.  
  816.  
  817. //---------------------------------------------------------------------------------
  818. // Function:    
  819. //    SA_MungeExtractURLParameter(var sURL, var sParamName)
  820. //
  821. // Synopsis:    
  822. //    Extract the value of a query string parameter. If the parameter does not exist an empty
  823. //    string is returned.
  824. //        
  825. //    The URL must be non-blank on input. If a blank URL is passed an error message is 
  826. //    displayed and a empty string is returned.
  827. //
  828. // Arguments:    
  829. //    sURL - Non blank URL that is to be changed. 
  830. //    sParamName - Name of QueryString parameter
  831. //
  832. // Returns:    
  833. //    Value of query string parameter, empty string if an error occurs.
  834. //
  835. //---------------------------------------------------------------------------------
  836. function SA_MungeExtractURLParameter(sURL, sParamName)
  837. {
  838.     var i;
  839.     var oException;
  840.     var sParamValue = "";
  841.  
  842.     //
  843.     // Validate arguments
  844.     //
  845.     if ( sURL == null )
  846.     {
  847.         sURL = "";
  848.     }
  849.     if ( (typeof sURL) != "string" )
  850.     {
  851.         sURL = "" + sURL;
  852.     }
  853.  
  854.     if ( sParamName == null )
  855.     {
  856.         SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is null");
  857.         return "";
  858.     }
  859.     if ( (typeof sParamName) != "string" )
  860.     {
  861.         sParamName = "" + sParamName;
  862.     }
  863.     
  864.  
  865.     if ( sURL.length <= 0 )
  866.     {
  867.         SA_TraceOut("SA_MungeExtractURLParameter", "Invalid argument: sURL is empty");
  868.         return "";
  869.     }
  870.  
  871.  
  872.     if ( sParamName.length <= 0 )
  873.     {
  874.         SA_TraceOut("SA_MungeExtractURLParameter", "Invalid argument: sParamName is empty");
  875.         return "";
  876.     }
  877.  
  878.     //
  879.     // Scan for the Parameter
  880.     //
  881.     try
  882.     {
  883.         var sParamToken = "?"+sParamName+"=";
  884.  
  885.         i = sURL.indexOf(sParamToken);
  886.         if ( i < 0 )
  887.             {
  888.             sParamToken = "&"+sParamName+"=";
  889.             i = sURL.indexOf(sParamToken);
  890.             }
  891.     
  892.         if ( i > 0 )
  893.         {
  894.  
  895.             sParamValue = sURL.substring(i+sParamToken.length);
  896.  
  897.             i = sParamValue.indexOf("&");
  898.             if ( i > 0 )
  899.                 {
  900.                 sParamValue = sParamValue.substring(0, i);
  901.                 }
  902.         }
  903.     }
  904.     catch(oException)
  905.         {
  906.         SA_TraceOut("SA_MungeExtractURLParameter", 
  907.             "SA_MungeExtractURLParameter encountered exception: " 
  908.             + oException.number + " " + oException.description);
  909.         }
  910.     return sParamValue;
  911. }
  912.  
  913.  
  914. //---------------------------------------------------------------------------------
  915. // Function:    
  916. //    SA_EnableButton(var oButton, var bEnabled)
  917. //
  918. // Synopsis:    
  919. //    Change the enabled state for a button. oButton must be a DOM reference to a object
  920. //    of type='button'.
  921. //        
  922. // Arguments:    
  923. //    oButton - DOM Reference object ot a button
  924. //    bEnabled - boolean flag indicating if the button should be enabled (true) or disabled(false)
  925. //
  926. // Returns:    
  927. //    true to indicate success, false to indicate errors.
  928. //
  929. //---------------------------------------------------------------------------------
  930. function SA_EnableButton(oButton, bEnable)
  931. {
  932.     var oException;
  933.     try 
  934.     {
  935.         //
  936.         // Validate arguments
  937.         if ( oButton == null )
  938.         {
  939.             SA_TraceOut("SA_EnableButton", "oButton argument was null.");
  940.             return false;
  941.         }
  942.         if ( oButton.type != "button" )
  943.         {
  944.             SA_TraceOut("SA_EnableButton", "oButton.type is invalid, requires oButton.type='button'. Type was: " +oButton.type);
  945.             return false;
  946.         }
  947.         if ( bEnable != true && bEnable != false )
  948.         {
  949.             SA_TraceOut("SA_EnableButton", "bEnable argument was invalid, required to be either true or false");
  950.             return false;
  951.         }
  952.  
  953.         //
  954.         // Set the button disabled state, the inverse of the bEnabled argument
  955.         oButton.disabled = ( (bEnable) ? false : true );
  956.  
  957.         oButton.value = oButton.value;
  958.  
  959.         return true;
  960.     }
  961.     catch(oException)
  962.     {
  963.         SA_TraceOut("SA_EnableButton", 
  964.                     "Encountered exception: " 
  965.                     + oException.number + " " + oException.description);
  966.         return false;
  967.     }
  968.     
  969. }
  970.  
  971. ///////////////////////////////////////////////////////////////////////////////////////////////////
  972. // EscapeArg(
  973. // 
  974. // @jfunc This function escapes (i.e., legalize) the specified argument.
  975. //
  976. // @rdesc Newly formatted argument
  977. //
  978. // @ex Usage: strShow = EscapeArg("Is <> : * \" this?");
  979. ///////////////////////////////////////////////////////////////////////////////////////////////////
  980. function EscapeArg(
  981.     strArg
  982. )
  983. {
  984.     return EncodeHttpURL(strArg, 1);
  985.     
  986.     // Validate input.
  987.     if (null == strArg)
  988.         return null;
  989.  
  990.     // Convert %xx to %u00xx
  991.     var strEscArg = escape( strArg );
  992.     strEscArg = strEscArg.replace(/(%)([0-9A-F])/gi, "%u00$2");
  993.     strEscArg = strEscArg.replace(/\+/g, "%u002B");        // Else + becomes space.
  994.     return strEscArg;
  995. }
  996.  
  997. ///////////////////////////////////////////////////////////////////////////////////////////////////
  998. // UnicodeToUTF8
  999. // 
  1000. // @jfunc This function converts a string from Unicode to UTF-8 encoding.
  1001. //
  1002. // @rdesc Newly formatted string
  1003. //
  1004. // @ex Usage: strShow = UnicodeToUTF8("\u33C2\u7575\u8763");
  1005. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1006. function UnicodeToUTF8(
  1007.     strInUni        // @parm The string in Unicode encoding
  1008. )
  1009. {
  1010.     // Validate input.
  1011.     if (null == strInUni)
  1012.         return null;
  1013.         
  1014.     // The following line fixes a problem when the input is not a valid java script string object.
  1015.     // This can happen, for example, if the caller passes the output of QueryString() to this 
  1016.     // function; InterDev pops up the following error message if this happen: the error code is 
  1017.     // object doesn't support this property or method.  This line of code makes sure we use a valid
  1018.     // java script string object.
  1019.     var strUni = ""+strInUni;
  1020.     
  1021.     // Map string.
  1022.     var strUTF8 = "";    // Destination (UTF8 encoded string)
  1023.  
  1024.     // Convert Unicode to UTF-8
  1025.     for(var i=0; i<strUni.length; i++)
  1026.     {
  1027.         var wchr = strUni.charCodeAt(i);        // Unicode value.
  1028.  
  1029.         if (wchr < 0x80)
  1030.         {
  1031.             // A char in range 0-0x7f don't need any work. just copy the char.
  1032.             strUTF8 += strUni.charAt(i);
  1033.         }
  1034.         else if (wchr < 0x800)
  1035.         {
  1036.             // A char in range 0x80-0x7ff is converted to 2 bytes as follows:
  1037.             // 0000 0yyy xxxx xxxx -> 110y yyxx   10xx xxxx 
  1038.             
  1039.             var chr1 = wchr & 0xff;            // low byte.
  1040.             var chr2 = (wchr >> 8) & 0xff;    // high byte.
  1041.  
  1042.             strUTF8 += String.fromCharCode(0xC0 | (chr2 << 2) | ((chr1 >> 6) & 0x3));
  1043.             strUTF8 += String.fromCharCode(0x80 | (chr1 & 0x3F));
  1044.         }
  1045.         else 
  1046.         {
  1047.             // A char in range 0x800-0xffff is converted to 3 bytes as follows:
  1048.             // yyyy yyyy xxxx xxxx -> 1110 yyyy   10yy yyxx   10xx xxxx 
  1049.  
  1050.             var chr1 = wchr & 0xff;            // low byte.
  1051.             var chr2 = (wchr >> 8) & 0xff;    // high byte.
  1052.  
  1053.             strUTF8 += String.fromCharCode(0xE0 | (chr2 >> 4));
  1054.             strUTF8 += String.fromCharCode(0x80 | ((chr2 << 2) & 0x3C) | ((chr1 >> 6) & 0x3));
  1055.             strUTF8 += String.fromCharCode(0x80 | (chr1 & 0x3F));
  1056.         }
  1057.     }
  1058.  
  1059.     return strUTF8;
  1060. }
  1061.  
  1062. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1063. // EscapeHttpURL
  1064. // 
  1065. // @jfunc This function escapes the illigal http chars.
  1066. //
  1067. // @rdesc Newly formatted string
  1068. //
  1069. // @ex Usage: strShow = EscapeHttpURL("Is <> \" this a / folder \ name?");
  1070. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1071. function EscapeHttpURL( 
  1072.     strHttpURL,                // @parm URL to escape
  1073.     nFlags                    // @parm Encoding flags.
  1074. )
  1075. {
  1076.     // Validate input.
  1077.     if (null == strHttpURL)
  1078.         return null;
  1079.         
  1080.     // Init default argument.
  1081.     if (null == nFlags)
  1082.         nFlags = 0;
  1083.  
  1084.     // The following line fixes a problem when the input is not a valid java script string object.
  1085.     // This can happen, for example, if the caller passes the output of QueryString() to this 
  1086.     // function; InterDev pops up the following error message if this happen: the error code is 
  1087.     // object doesn't support this property or method.  This line of code makes sure we use a valid
  1088.     // java script string object.
  1089.     var strURL = ""+strHttpURL;
  1090.  
  1091.     // Unescape string.
  1092.     var strEsc = "";
  1093.     for(var i=0; i<strURL.length; i++)
  1094.     {
  1095.         var bEscape = false;
  1096.         var chr        = strURL.charAt(i);
  1097.         var chrCode = strURL.charCodeAt(i);
  1098.  
  1099.         switch(chr)
  1100.         {
  1101.         case '"':
  1102.         case '#':
  1103.         case '&':
  1104.         case '\'':
  1105.         case '+':
  1106.         case '<':
  1107.         case '>':
  1108.         case '\\':
  1109.             bEscape = true;
  1110.             break;
  1111.  
  1112.         case '%':
  1113.             if (nFlags & 0x1)
  1114.                 bEscape = true;
  1115.             break;    
  1116.  
  1117.         default:
  1118.             if ((chrCode > 0x00 && chrCode <= 0x20) ||
  1119.                 (chrCode > 0x7f && chrCode <= 0xff))
  1120.                 bEscape = true;
  1121.             break;
  1122.         }
  1123.  
  1124.         // escape() doesn't escape the '+' sign.
  1125.         if ('+' == chr)
  1126.             strEsc += "%2B"; 
  1127.  
  1128.         else if (bEscape)
  1129.             strEsc += escape(chr);
  1130.  
  1131.         else
  1132.             strEsc += chr;
  1133.     }
  1134.  
  1135.     // All done.
  1136.     return strEsc;
  1137. }
  1138.  
  1139. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1140. // EncodeHttpURL(
  1141. // 
  1142. // @jfunc This function legalizes an http url.
  1143. //
  1144. // @rdesc Newly formatted name
  1145. //
  1146. // @ex Usage: strShow = EncodeHttpURL("Is [] {} $24 $22 it a folder$3F");
  1147. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1148. function EncodeHttpURL(
  1149.     strHttpURL,        // @parm File folder name to be encode.
  1150.     nFlags            // @parm Encoding flags.
  1151. )
  1152. {
  1153.     // Validate input.
  1154.     if (null == strHttpURL)
  1155.         return null;
  1156.  
  1157.     // Init default argument.
  1158.     if (null == nFlags)
  1159.         nFlags = 0;
  1160.  
  1161.     // The following line fixes a problem when the input is not a valid java script string object.
  1162.     // This can happen, for example, if the caller passes the output of QueryString() to this 
  1163.     // function; InterDev pops up the following error message if this happen: the error code is 
  1164.     // object doesn't support this property or method.  This line of code makes sure we use a valid
  1165.     // java script string object.
  1166.     var strURL = ""+strHttpURL;
  1167.  
  1168.     // Convert to UTF-8
  1169.     strURL = UnicodeToUTF8( strURL );
  1170.  
  1171.     // Percent escape.
  1172.     strURL = EscapeHttpURL( strURL, nFlags );
  1173.  
  1174.     // All done.
  1175.     return strURL;
  1176. }
  1177.  
  1178.